/**
 * Created by MR on 2016/4/27 027.
 * Role 角色名，3个角色权限不同可操作的面板不同，角色名可双语显示
 * User 用户名，不影响权限（用户可操作的面板）
 * var Role = '<%=session.getAttribute("role") %>';
 * var User= '<%=session.getAttribute("user_name")%>';
 */
"use strict";

$(function() {
    swichRole();
    $("#menuinx>li").click(menuIndexClickHandle);
});
function swichRole(e){
    var nowrole,ct;
    if(Role==undefined||Role=="null"||Role==null||Role==""){
        $("#nav_userhead").hide();
        setRoleContent();
    }else if(typeof(e)=="undefined"){
        nowrole=Role;
        if(nowrole=="teacher"){
            ct="ms_switchRole_t";
        }else{
            ct="ms_switchRole_s";
        }
        setRoleContent();
        $("#nav_userhead").show();
    }else if(e=="teacher"){
        Role = "student";
        nowrole="student";
        ct="ms_switchRole_s";
        setRoleContent();
        $("#nav_userhead").show();
    }else{
        Role = "teacher";
        nowrole="teacher";
        ct="ms_switchRole_t";
        setRoleContent();
        $("#nav_userhead").show();
    }
    $("#nav_userhead>div.UserContent>button").attr("data-role",nowrole);
    $("#nav_userhead>div.UserContent>button").html(langThis(ct)+' <span class="glyphicon glyphicon-retweet"></span>');
}
function setRoleContent() {
    var jump = function(s) {
        var act=s.split("=")[1];
        if(act && act.length){
            $("#menuinx>li[role=presentation]").each(function(index, e) {
                if (e.id == act) {
                    $(e).removeClass("active").addClass("active");
                } else {
                    $(e).removeClass("active");
                }
            });
        }
        $("#rightIframe").attr("src", s.split("?")[0]);
    };

    if (Role == "teacher") {
         $("#score").hide();
        $("#onlinelab").hide();
        $("#homewk").hide();
        $("#course").show();
        //先隐藏作业批改及下载桌面
        $("#downloads").show();
        $("#labcorrecting").show();
        $("#course").show();
        $("#recruitstmg").show();
        jump("courseManage?=course");
    } else{
        $("#course").hide();
        //先隐藏我的作业和成绩下载
        $("#downloads").show();
        $("#homewk").show();
        $("#score").show();
        $("#labcorrecting").hide();
        $("#recruitstmg").hide();
        $("#onlinelab").show();
        jump("stuLesson?=onlinelab");
    }
}

function setiframeHeight(ht) {
    $(".height100").height(ht);
}

function menuIndexClickHandle(idstring) {
    var id = this.id;
    var url = "";
    switch (id) {
        case "course":
            url = "courseManage";
            break;
        case "score":
            url = "scoreManage";
            break;
        case "labcorrecting":
            url = "labcorrecting";
            break;
        case "homewk":
            url = "homewks";
            break;
        case "onlinelab":
            url = "stuLesson";
            break;
        case "resource":
            url = "trainingresources";
            break;
        case "downloads":
            url = "download.jsp";
            break;
        case "recruitstmg":
            url="recruitstmg";
        break;
        default:
            break;
    }
    $("#rightIframe").attr("src", url);
}

function setChooseContent() {
    $("#rightIframe").attr("src", "choose");
}
function setScoreContent(){
    $("#menuinx li").removeClass('active');
    $("#score").addClass('active');
}
//子页面提示信息
function parentLayermsg(msg,op){
    layer.msg(msg,op);
}
//子页面确认弹窗
function parentLayerConfirm(title,msg,btn1,btn2,fun1,fun2){
    // title{text,{color,background-color}}
    layui.use('laydate');
    layer.confirm(msg, {
		btn: [btn1, btn2]
	}, fun1, fun2);
    // 标题
    var header=$("div.layui-layer.layui-layer-dialog.layer-anim>div.layui-layer-title");
    if(typeof(title)=="string"){
        header.html(title);
        return;
    }
    header.html(title.text);
    header.css(title.css);
}
//子页面加载框
function parentLoading(){
    return layer.load(2, {
			shade: [0.5, "#eee"]
		});
}
//子页面清楚layer弹窗
function parentCloseAll() {
    layer.closeAll();
}